"""
新建线索页面
"""
from config.config import HOST
from selenium.webdriver.common.by import By
from pages.base_page import BasePage


class NewCluePage(BasePage):
    """在新建线索页面做的操作 输入公司名 输入联系人 点击保存"""
    url = "http://{}/crm/index.php?m=leads&a=add".format(HOST)
    company_name_locator = (By.ID, 'name')
    contacts_name_locator = (By.ID, 'contacts_name')
    save_btn_locator = (By.CSS_SELECTOR, '#form1 > table > tfoot > tr > td > input:nth-child(1)')
    phone_locator = (By.CSS_SELECTOR, '#mobile')
    email_style_locator = (By.CSS_SELECTOR, '#email')
    input_profession_locator = (By.ID, 'position')
    def input_company_name(self, company_name):
        """输入公司名"""
        self.driver.find_element(*self.company_name_locator).send_keys(company_name)

    def input_contacts_name(self, contacts_name):
        """输入联系人姓名"""
        self.driver.find_element(*self.contacts_name_locator).send_keys(contacts_name)

    def input_11phone(self,phone):
        """输入手机为11位数字字符"""
        self.driver.find_element(*self.phone_locator).send_keys('17340001808')

    def click_save_btn(self):
        """点击保存按钮"""
        self.driver.find_element(*self.save_btn_locator).click()

    def input_email_style(self,email):
        """添加线索-邮箱含@xxx.com格式"""
        self.driver.find_element(*self.email_style_locator).send_keys(email)

    def input_profession(self,profession):
        """填写职业为1个字符"""
        self.driver.find_element(*self.input_profession_locator).send_keys(profession)

    def alert(self):
        """出现弹窗，点击确定"""
        self.driver.switch_to.alert.accept()